/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tchepannou.limbe.helper;

/**
 *
 * @author herve
 */
public class CamelCaseHelper
{
    public static String fromUnderscore(String s)
    {
       String[] parts = s.split("_");
       StringBuilder sb = new StringBuilder ();
       for (String part : parts)
       {
           if (sb.length() > 0)
           {
               sb.append(toProperCase (part));
           }
           else
           {
               sb.append(part);
           }
       }
       return sb.toString ();
    }
    
    public static String toUnderscore(String s)
    {
        String regex = "([a-z])([A-Z])";
        String replacement = "$1_$2";
        return s.replaceAll(regex, replacement).toLowerCase ();
    }

    private static String toProperCase(String s)
    {
        return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
    }
    
}
